<?php
        require_once 'db.php';
        $data = file ('http://epab.posten.no/Norsk/Nedlasting/_Files/tilbud5.txt');
        $sql = 'INSERT INTO postnr (postnr, poststed) values (?, ?)';
        $sth = $db->prepare($sql);
        foreach ($data as $poststed) {
            $postinfo = preg_split("[\t]", $poststed);
            $sth->execute(array($postinfo[0], $postinfo[1]));
        }
        
        echo "<p>POSTSTED ADDED</p>";
        
        $countries = array();
        $data = file('http://www.listofcountriesoftheworld.com/');

        foreach ($data as $country) {
            if (strstr($country, '<a href="')) {
                $countries[] = substr($country, 18, -5);
            }
        }
        for ($i = 257; $i < sizeof($countries) + 11; $i++) {
            $del = array_pop($countries);
        }
        
        $sql = 'INSERT INTO countries (country) VALUES (?)';
        $sth = $db->prepare($sql);
        for($i = 0; $i < 257; $i++){
            $sth->execute(array ($countries[$i]));
        }
        
        echo "<p>COUNTRIES ADDED</p>";
        echo "<a href=\"index.php\">To Home</a>";
?>